import random
from datetime import datetime, timedelta
from decimal import Decimal
"""
a = 3 * 10 ** 8
"""
"""
# 对序列进行分档
end = 27
seg = 5
step = end/seg
last = 0
start = step
print(step)
while start <= end:
    print((last, int(start)))
    last = int(start)
    start = start + step
"""

"""
for i in range(10):
    print(i)
# 结论：range不含尾巴
"""


"""
i = 15.0012
print(round(i, 5))
j = 15.00004

print(round(i, 3)/ round(j,3))

i = 55
j = 55 % 10
print(i-j)
# 结论：round的参数表示小数点后的位数
"""


def weight_average_distribute(weight, n):
    # 取整均分,分成n档
    num_base = n * 10
    result_list = [int(weight/num_base) * 10]*n
    rest_weight = weight % num_base
    i = 0
    while rest_weight > 0:
        result_list[i] += 10
        rest_weight -= 10
        i += 1
    return result_list


def round_test():
    i = 7.0
    j = 15.0
    i_r = round(i/(i + j) + 0.05, 1)
    print(i_r)


def random_num_test():
    dt_now = datetime.now()
    last_num = 0
    for i in range(5):
        dt = dt_now + timedelta(seconds=last_num)
        print(dt)
        r = random.randint(40, 65)
        last_num += r


def decimal_5():
    # 4舍5入
    value =Decimal(str(0))
    target = Decimal(str(1))
    point_5 = Decimal(str(0.5))
    result = float(int(value / target + point_5) * target)
    print(result)


def decimal_round_to():
    value = 26.9
    target = 0.5
    value = Decimal(str(value))
    target = Decimal(str(target))
    round_1 = round(value / target)
    int_1 = int(round_1)
    rounded = float(int_1 * target)
    print(rounded)

if __name__ == '__main__':
    #print(weight_average_distribute(10, 2))
    #round_test()
    #random_num_test()
    decimal_5()
    #decimal_round_to()
